﻿<h3 id="hTitle">@ViewBag.Message</h3>

 <table border="1" width="100%">

 @model List<PYS.course>

 @{
     PYS.PYSEntities entities = new PYS.PYSEntities();
     string userId = User.Identity.Name; 
     <tr>
     <td></td>
     @for (int dayIdx = 1; dayIdx <= 6; dayIdx++){
      <td>@String.Format("{0}",((DayOfWeek)dayIdx)).Substring(0,3)</td>
     }
     </tr>

         for (int hour = 10; hour < 20; hour++)
         {
            <tr>
            <td>@String.Format("{0}:00", hour)</td>
             @for (int dayIdx = 1; dayIdx <= 6; dayIdx++)
            {
                var course = Model.FirstOrDefault(c => c.weekDay == dayIdx && c.startHour == new TimeSpan(hour, 0, 0));
                var courseID = 0;
                if (course != null)
                {
                    courseID = course.courseID;
                }

                PYS.voteUser haveVoted = entities.voteUsers.FirstOrDefault(x => x.courseID == courseID && x.userID == userId);

                 
              <td style="text-align:center">
              @if (Model.Exists(c => c.weekDay == dayIdx &&
                                c.startHour == new TimeSpan(hour, 0, 0) &&
                              DateTime.Now.DayOfWeek.CompareTo((DayOfWeek)dayIdx)>0))
              {
                  <a href="Report/Report/@courseID"> <img class="voteButton" alt="raport" src="Content/images/report.png"/></a>
              }
              else
              {
                  if (Model.Exists(c => c.weekDay == dayIdx &&
                                  c.startHour == new TimeSpan(hour, 0, 0) &&
                                DateTime.Now.DayOfWeek.CompareTo((DayOfWeek)dayIdx) < 0))
                  {
                      if (haveVoted != null)
                      {
                          <span>Ai votat!</span>
                      }
                      else
                      {
                          <a href="Vote/Vote?id1=@courseID&id2=1"><img class="voteButton"alt="vot" src="Content/images/stamp.png" /></a>
                      }
                  }
                  else
                  {
                      if (Model.Exists(c => c.weekDay == dayIdx &&
                                  c.startHour == new TimeSpan(hour, 0, 0) &&
                                DateTime.Now.DayOfWeek.CompareTo((DayOfWeek)dayIdx) == 0 &&
                               c.startHour >= new TimeSpan(DateTime.Now.Hour + 2, 0, 0)))
                      {
                           if (haveVoted != null)
                              {
                                  <span>Ai votat!</span>
                              }
                              else
                              {
                                  <a href="Vote/Vote?id1=@courseID&id2=1"><img class="voteButton"alt="vot" src="Content/images/stamp.png" /></a>
                              }
                      }
                      else
                      {
                          if (Model.Exists(c => c.weekDay == dayIdx &&
                                      c.startHour == new TimeSpan(hour, 0, 0) &&
                                    DateTime.Now.DayOfWeek.CompareTo((DayOfWeek)dayIdx) == 0 &&
                                   c.startHour < new TimeSpan(DateTime.Now.Hour + 2, 0, 0)))
                          {
                                            <a href="Report/Report/@courseID"><img class="voteButton" alt="raport" src="Content/images/report.png" /></a>
                          }

                      }
                  }
              }
              </td>
            }
            </tr>
        }
        }
 </table>